package com.qymerge.manage.base.dao.impl;

import com.qymerge.manage.base.dao.IStoredProcedureDao;
import com.qymerge.manage.base.ro.BDMSaleLinesRO;
import com.qymerge.manage.base.ro.MetaLogsRO;
import com.qymerge.manage.base.ro.MetaProfitTableTemplateRO;
import com.qymerge.manage.core.dao.BaseDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * <p>Title: 执行存储过程</p>
 * <p>Description: </p>
 *
 * @author Xiao
 * @version 1.0.0
 * @date 2025/5/28 17:33
 */
@Repository
public class StoredProcedureDaoImpl implements IStoredProcedureDao {

    @Autowired
    private JdbcTemplate jdbcTemplate2;

    @Override
    public List<BDMSaleLinesRO> getBDMSaleLinesByBillCode(String billCode, int page, int pageSize) {
        String sql = "call z_event_table(?,?,?)";
        return jdbcTemplate2.query(sql, new Object[]{billCode, page, pageSize}, new RowMapper<BDMSaleLinesRO>(){

            @Override
            public BDMSaleLinesRO mapRow(ResultSet rs, int i) throws SQLException {
                String event_name = rs.getString(1);
                String date_key  = rs.getString(2);

                Date event_time  = rs.getDate(3);
                return new BDMSaleLinesRO(event_name, event_time, date_key);
            }
        });
    }

    @Override
    public void dwd_MCRS_MDM_sp_Voucher(String XPeriodCode) {
        String sql = "call dwd_MCRS_MDM_sp_Voucher(" + XPeriodCode + ")";
        jdbcTemplate2.execute(sql);
    }

    @Override
    public void dwd_MCRS_BDM_sp_SaleLines(String XPeriodCode) {
        String sql = "call dwd_MCRS_BDM_sp_SaleLines("+XPeriodCode+")";
        jdbcTemplate2.execute(sql);
    }

    @Override
    public void dwd_MCRS_MDM_Sp_ActualDataExtra(String XPeriodCode) {
        String sql = "call dwd_MCRS_MDM_Sp_ActualDataExtra("+XPeriodCode+")";
        jdbcTemplate2.execute(sql);
    }

    @Override
    public void dwd_MCRS_MDM_sp_InventoryBalance(String XPeriodCode) {
        String sql = "call dwd_MCRS_MDM_sp_InventoryBalance("+XPeriodCode+")";
        jdbcTemplate2.execute(sql);
    }

    @Override
    public void dwd_MCRS_Report_SP_In_Out_Cost() {
        String sql = "{ call dwd_MCRS_Report_SP_In_Out_Cost() }";
        jdbcTemplate2.execute(sql);
    }

    @Override
    public void dwd_MCRS_Report_SP_In_Sales() {
        String sql = "{ call dwd_MCRS_Report_SP_In_Sales() }";
        jdbcTemplate2.execute(sql);
    }


}
